import React,{useEffect,useState} from 'react';
import {Card, Descriptions,Steps} from 'antd';
import {GridContent} from '@ant-design/pro-layout';
import {channelList,websiteList} from '@/utils/constant';
import {getRecruitment} from '../service';

const Hire = ({info,oid}) => {
  const { Step } = Steps;
  const [data,setData] = useState([]);
  const [current,setCurrent] = useState(0);

  useEffect(() => {
    getRecruitment(oid).then(res => {
      let hadDayArray = res.filter(item => item.day !== null);
      setCurrent(res.findIndex((item) => item.title === hadDayArray[hadDayArray.length - 1].title) + 1);
      if (res[res.length - 1].day)
        setCurrent(res.length);
      setData(res);
    });
  }, []);

  return (
    <>
      <GridContent>
        <Card title="招聘进度" style={{marginBottom: 24}} bordered={false}>
          <Steps current={current}>
            {
              data.map((item,index) => {
                return (
                  <Step title={item.title} key={index} description={item.day}/>
                )
              })
            }
          </Steps>
        </Card>
        <Card title="招聘信息" style={{marginBottom: 24}} bordered={false}>
          <Descriptions>
            <Descriptions.Item label="招聘渠道">{channelList.find(e => info.channel === e.value)?.label}</Descriptions.Item>
            <Descriptions.Item label="推荐人(内部)">{info.innerReferrer}</Descriptions.Item>
            <Descriptions.Item label="推荐人(外部)">{info.outerReferrer}</Descriptions.Item>
            <Descriptions.Item label="招聘网站">{websiteList.find(e => info.recruitmentWeb === e.value)?.label}</Descriptions.Item>
          </Descriptions>
        </Card>
      </GridContent>
    </>
  );
};
export default Hire;
